package com.scqzy.shengchunqiang.sword2offer.day04;

/**
 * @Description: 剑指 Offer 53 - I. 在排序数组中查找数字 I
 * @Author 盛春强
 * @Date 2021/8/11 19:53
 */
public class Search {
    public int search(int[] nums, int target) {
        int c = 0;
        int left = 0;
        int right = nums.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] >= target) {
                right = mid;
            } else if (nums[mid] < target) {
                left = mid + 1;
            }
        }
        while (left < nums.length && target == nums[left++]) {
            c++;
        }
        return c;
    }
}
